require"bit"
function Enum(list)
    local enum = {}
    for i, v in ipairs(list) do
        if type(v) == "string" then
            enum[v] = i
        else
            if not v.value then
                v.value = i
            end
            enum[v.key] = i
        end
    end
    enum.list = list
    return enum
end

local function makeEnumMaskKey(prekey, idx, prenum, groups, enumMask)
    local group = groups[idx]
    local key = prekey
    if idx == #groups then
        if prekey == "" then
            key = "any"
        end
        enumMask[key] = prenum * group.count
    else
        makeEnumMaskKey(key, idx + 1, prenum * group.count, groups, enumMask)
    end
    for i = 1, #group.list do
        local key = prekey.."_"..group.list[i]
        if prekey == "" then
            key = group.list[i]
        end
        local num = prenum * group.count + i

        if idx == #groups then
            enumMask[key] = num
        else
            makeEnumMaskKey(key, idx + 1, num, groups, enumMask)
        end
    end
end
-- 枚举掩码，类似于位掩码，将多个枚举合并到一个值中
function EnumMask(...)
    local enumMaskGroups = {}
    local enumMask = {}
    for _, list in ipairs({...}) do
        local group = {}
        group.list = list
        group.count = #list + 1
        table.insert(enumMaskGroups, group)
    end

    makeEnumMaskKey("", 1, 0, enumMaskGroups, enumMask)
    return enumMask
end

local list = {
    "Horizontal",
    "Vertical"
}
LayoutType = Enum(list)

SpriteDrawType = Enum{
    "Simple",
    "Scale9"
}

DynamicAtlasDefaultSize = 1204

function BitMask(list)
    local tbl = {}
    tbl.list = list
    for i, k in ipairs(list) do
        tbl[k] = bit.lshift(1, i - 1)
    end
    return tbl
end
VarTypes = Enum{
    {
        key = "Number",
        text = "数值"
    },
    {
        key = "String",
        text = "文本"
    },
    {
        key = "List",
        text = "列表"
    },
    {
        key = "Table",
        text = "表单"
    },
    {
        key = "Boolean",
        text = "布尔值"
    },
    {
        key = "Selection",
        text = "选项"
    },
    {
        key = "MultiSelection",
        text = "多选选项"
    },
    {
        key = "ListIndex",
        text = "列表引用"
    },
    {
        key = "TableIndex",
        text = "表单引用"
    }
}

UpdateMode = Enum{
    {
        key = "Immediately",
        text = "立即",
    },
    {
        key = "NextTick",
        text = "下一帧"
    },
    {
        key = "Idle",
        text = "闲时更新"
    },
    {
        key = "OnGet",
        text = "获取时"
    }
}